package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.dto.SetmealDto;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public R setmeal(@RequestBody SetmealDto setmealDto) {
        R r = setmealService.setmeal(setmealDto);
        return r;
    }

    @GetMapping("/page")
    public R page(Integer page, Integer pageSize, String name) {
        R r = setmealService.findPage(page, pageSize, name);
        return r;
    }

    //  修改套餐 1 回显
    @GetMapping("/{id}")
    public R selectBysetmealId(@PathVariable Long id) {
        R r = setmealService.selectBysetmealId(id);
        return r;
    }

    //  修改 2  修改保存
    @PutMapping
    public R update(@RequestBody SetmealDto setmealDto) {
        R r = setmealService.update(setmealDto);
        return r;
    }

    //  套餐 批量启售/停售
    @PostMapping("/status/{id}")
    public R status(Long[] ids, @PathVariable Integer id) {
        return setmealService.status(ids, id);
    }

    // 套餐 批量删除以及单个删除
    @DeleteMapping
    public R deleteById(Long ids) {
        return setmealService.deleteById(ids);
    }

    @GetMapping("/list")
    public R list(Long categoryId, Integer status) {
        R r = setmealService.list(categoryId, status);
        return r;
    }
}
